home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Snippets / DynamoArray 1.0 / DynamoArrayTest.c++ < prev   
Encoding:
C/C++ Source or Header  |  1994-05-04  |  1.4 KB  |  61 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.         DynamoArrayTest.c++
  4.         
  5.         Test file using the DynamoArray class...
  6.         Shows the usage of the class, though minimally, using the standard C++
  7.         input/output. You can use the class in any app, actually, not just
  8.         standard C++ i/o applications (read: use in your Mac apps too).
  9.  
  10.         This is public domain.
  11.  
  12.         by: Hiep Dam, 3G Software
  13.         Bug reports, improvements, witty remarks, are all welcomed and
  14.         encouraged.
  15.         Contacting the author: AOL:      starlabs
  16.                                Delphi:   starlabs
  17.                                Internet: starlabs@aol.com, starlabs@delphi.com
  18.  
  19.         Last update: 5/4/94
  20.             
  21. */
  22.  
  23.  
  24. #include <iostream.h>
  25. #include "DynamoArray.h"    // Currently the array holds *longs*. See the header file...
  26.  
  27.  
  28. void main() {
  29.     DynamoArray theList(20);    // Create a dynamoarray with 20 spaces pre-allocated
  30.     DynamoArray aCopy;
  31.     long j;
  32.  
  33.     cout << "Test" << endl << endl;
  34.     
  35.     // Add 10 numbers, from 0 to 9, to the array
  36.     for (short i = 0; i < 10; i++)
  37.         theList.Append(i);
  38.     
  39.     // Add another 10 numbers, from -1 to -9
  40.     for (i = 0; i < 10; i++)
  41.         theList.Append(-(i+1));
  42.     
  43.     // Make a copy, well, actually assignment...
  44.     aCopy = theList;
  45.  
  46.     // Remove elements of array, in order
  47.     cout << "Removal in order:" << endl;
  48.     while (theList.SizeOf() != 0) {
  49.         theList.Remove(j, 0);
  50.         cout << j << ", ";
  51.     }
  52.     cout << endl << endl;
  53.     
  54.     // Remove elements of array, randomly
  55.     cout << "Removal randomly:" << endl;
  56.     while (aCopy.SizeOf() != 0) {
  57.         aCopy.RandomRemove(j);
  58.         cout << j << ", ";
  59.     }
  60.     cout << endl;
  61. }